﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Windows.Forms;
using RibbonEditor.AppCode;

namespace RibbonEditor.CommandUIDefinitionClasses
{
    public class MaxSize : ICommandUIDefinition, IXmlBuildable
    {
        public string GroupId { get; set; }
        public string Id { get; set; }
        public int? Sequence { get; set; }
        public string Size { get; set; }

        public MaxSize()
        {}

        public MaxSize(XmlNode node):this()
        {
            try
            {
                this.GroupId = XmlHelper.GetAttribute(node, "GroupId");
                this.Id = XmlHelper.GetAttribute(node, "Id");
                this.Sequence = XmlHelper.GetNullableIntAttribute(node, "Sequence");
                this.Size = XmlHelper.GetAttribute(node, "Size");
            }
            catch (Exception error)
            {
                MessageBox.Show("An error occured: " + error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        public void AddNode(XmlNode commandUINode)
        {
            try
            {
                XmlNode maxSizeNode = XmlHelper.AddNode(commandUINode, "MaxSize");
                XmlHelper.AddAttribute(maxSizeNode, "GroupId", this.GroupId);
                XmlHelper.AddAttribute(maxSizeNode, "Id", this.Id);
                XmlHelper.AddAttribute(maxSizeNode, "Sequence", this.Sequence);
                XmlHelper.AddAttribute(maxSizeNode, "Size", this.Size);
            }
            catch (Exception error)
            {
                MessageBox.Show("An error occured: " + error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        public void BuildTreeViewElement(TreeNode parentNode)
        {
            try
            {
                TreeNode node = new TreeNode("MaxSize");
                node.Tag = this;
                node.ContextMenuStrip = ContextMenuStripHelper.BuildUICommandDefContextMenuStrip(node, null, true);

                parentNode.Nodes.Add(node);
            }
            catch (Exception error)
            {
                MessageBox.Show("An error occured: " + error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
